package com.stu.day12;

/**
 * 泛型接口
 * @author zy
 * @date 2025/2/10 15:08
 */
public interface IGenericDao<T> {  // 顶层泛型接口
    void save(T t);
}
class IGenericDaoImp<T> implements IGenericDao<T> {  // 泛型接口实现类
    @Override
    public void save(T t) {
        System.out.println("1.连接db");
        System.out.println("2.打开事务");
        System.out.println("3.save:"+t);
        System.out.println("4.提交事务");
        System.out.println("5.关闭连接");
    }
}
// 实体类
class Student{}
class Teacher{}

// 业务接口继承顶层泛型接口
interface IStudentDao extends IGenericDao<Student> {
    void doSomething();
}
interface ITeacherDao extends IGenericDao<Teacher> {
    void doSomething();
}

// 业务类继承泛型接口实现类,实现业务接口
class StudentDaoImp extends IGenericDaoImp<Student> implements IStudentDao{
    @Override
    public void doSomething() {
        System.out.println("学生类方法...");
    }
}
class TeacherDaoImp extends IGenericDaoImp<Teacher> implements ITeacherDao{
    @Override
    public void doSomething() {
        System.out.println("老师类方法...");
    }
}
class Test{
    public static void main(String[] args) {
        Student s = new Student();
        Teacher t = new Teacher();

        StudentDaoImp sdi = new StudentDaoImp();
        sdi.save(s);
        sdi.doSomething();

        System.out.println("--------");
        TeacherDaoImp tdi = new TeacherDaoImp();
        tdi.save(t);
        tdi.doSomething();
    }
}